package com.nkym.controller;/*
 * @ClassName UserInterfaceController
 * @Desc TODO
 * @Author 19637
 * @Date 2023/4/23 18:49
 * @Version 1.0
 */

import com.nkym.common.BaseResponse;
import com.nkym.pojo.dto.IdRequest;
import com.nkym.pojo.dto.interfaceInfo.InterfaceInfoQueryRequest;
import com.nkym.pojo.entity.UserInterface;
import com.nkym.pojo.userInterface.UserInterfaceAssignRequest;
import com.nkym.pojo.vo.PageVo;
import com.nkym.pojo.vo.UserInterfaceVo;
import com.nkym.service.UserInterfaceService;
import com.nkym.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@Api(tags = "UserInterfaceInfo")
@RequestMapping("/urIf")
public class UserInterfaceController {
    @Resource
    UserInterfaceService userInterfaceService;

    @GetMapping("/get")
    @ApiOperation("id获取用户接口信息")
    public BaseResponse<UserInterface> get(IdRequest idRequest) {
        //todo
        return ResultUtil.success();
    }
    @GetMapping("/page")
    @ApiOperation("分页获取用户接口")
    public BaseResponse<PageVo<UserInterfaceVo>> pageQueryInterface(InterfaceInfoQueryRequest infoQueryRequest, HttpServletRequest request) {
        PageVo<UserInterfaceVo> data = userInterfaceService.pageQueryInterface(infoQueryRequest, request);

        return ResultUtil.success(data);
    }

    @GetMapping("/assign")
    @ApiOperation("首次分配接口给用户")
    public BaseResponse<UserInterface> assign(UserInterfaceAssignRequest assignRequest, HttpServletRequest request) {
        boolean assign = userInterfaceService.assign(assignRequest, request);
        if (assign) {
            return ResultUtil.success("分配成功");
        }
        return ResultUtil.fail("分配失败");
    }


}
